package com.xindacloud.sms.console.system.service;

import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.xindacloud.sms.console.system.entity.SmsUser;
import com.xindacloud.sms.console.system.service.impl.SmsUserServiceImpl;
import com.xindacloud.sms.console.system.utils.UserSessionHelp;
import com.xindacloud.sms.console.system.vo.UserRoleVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * Created with IntelliJ IDEA
 * User: 张家喻
 * Date: 2020/6/2
 * Time: 11:30
 * Description:
 */
@Service
public class CommonServiceImpl {

    @Autowired
    SmsUserServiceImpl smsUserService;

    public Integer fetchUserRoleLevel(Integer userId){
        List<UserRoleVO> userRoleVOS = smsUserService.queryUserRoleList(userId);
        if (CollectionUtils.isEmpty(userRoleVOS)) {
            return 0;
        }
        final Set<Integer> set = userRoleVOS.stream()
                .map(UserRoleVO::getRolePrivLevel)
                .collect(Collectors.toSet());
        return Collections.max(set);
    }

}
